<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddColumnStepIdStepCategoryIdInRepairOrderAffectedTaskTable extends AbstractMigration
{
    public function up()
    {
        $this->table('repair_order_affected_task')
            ->addColumn('entity_id', 'integer', ['limit' => 11, 'null' => false, 'comment' => '实体id', 'default' => 0])
            ->addColumn('step_category_id', 'integer', ['limit' => 11, 'null' => false, 'comment' => '环节id', 'default' => 0])
            ->addColumn('step_id', 'integer', ['limit' => 11, 'null' => false, 'comment' => '工序id', 'default' => 0])
            ->save();

        $this->execute('update repair_order_affected_task roat join task t on t.id = roat.task_id set roat.entity_id = t.entity_id,roat.step_category_id = t.step_category_id,roat.step_id = t.step_id where roat.step_category_id = 0 or roat.step_id = 0');
    }

    public function down()
    {
        $this->table('repair_order_affected_task')
            ->removeColumn('entity_id')
            ->removeColumn('step_category_id')
            ->removeColumn('step_id')
            ->save();
    }
}
